<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Durante</title>
    <description>The latest articles on DEV Community by Durante (@durante).</description>
    <link>https://dev.to/durante</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F98215%2Fbad7a398-1ce3-4e2a-bcb3-84616595bc0a.png</url>
      <title>DEV Community: Durante</title>
      <link>https://dev.to/durante</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/durante"/>
    <language>en</language>
    <item>
      <title>Why APIs Are the Unsung Heroes of App Development</title>
      <dc:creator>Durante</dc:creator>
      <pubDate>Thu, 28 Nov 2024 02:03:12 +0000</pubDate>
      <link>https://dev.to/durante/why-apis-are-the-unsung-heroes-of-app-development-3gek</link>
      <guid>https://dev.to/durante/why-apis-are-the-unsung-heroes-of-app-development-3gek</guid>
      <description>&lt;p&gt;Let’s talk about building an app—whether it’s a virtual office or a self-care app. One question always looms in the background: &lt;strong&gt;When are you going to create the API?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It’s not the most exciting part of development, I know. APIs often don’t get the love they deserve. After all, users don’t see them directly, and calculating their ROI can be tricky. If the API is working well, is it the API itself generating revenue, or is it the app or platform leveraging that API? &lt;/p&gt;

&lt;p&gt;It’s a bit of a chicken-and-egg scenario, isn’t it? But here’s the thing: APIs are like the roots of a tree—no roots, no fruit. And yet, they’re often treated as optional. &lt;strong&gt;Skipping the creation of a robust API is a shortcut that will almost always cost you more time and resources in the long run.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  The API Dilemma: A Common Bottleneck in App Development
&lt;/h2&gt;

&lt;p&gt;In many projects, clients want their apps developed &lt;strong&gt;ASAP&lt;/strong&gt; to stay competitive. And yes, it’s possible—we’ve built apps in as little as 3 to 6 months. But here’s where the problem arises: when we dive into coding the app at full speed, the lack of a proper API often slows things down. Missing endpoints, incomplete processes, or even an absent API foundation can throw the entire project roadmap off course.&lt;/p&gt;

&lt;p&gt;What ends up happening? We find ourselves &lt;strong&gt;building the API and the app simultaneously.&lt;/strong&gt; While this is manageable, it’s far from ideal. An API isn’t just another feature; it’s a separate, foundational project that deserves its own roadmap and focus.&lt;/p&gt;

&lt;p&gt;Even if you don’t have every endpoint ready from the start, having a solid API foundation—complete with &lt;strong&gt;security, authentication, authorization, documentation, and validation&lt;/strong&gt;—can unlock countless opportunities.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Invest in an API? The Long-Term Benefits
&lt;/h2&gt;

&lt;p&gt;A well-designed API isn’t just a backend tool; it’s a &lt;strong&gt;strategic asset&lt;/strong&gt;. Here are some of the key benefits:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. &lt;strong&gt;Unified Business Logic Across Channels&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;With an API, you have a single source of truth for your business logic. This means you can build:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mobile apps&lt;/li&gt;
&lt;li&gt;Web applications&lt;/li&gt;
&lt;li&gt;Desktop applications&lt;/li&gt;
&lt;li&gt;Plugins&lt;/li&gt;
&lt;li&gt;Integrations with third-party platforms
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Instead of reimplementing logic across different platforms, you can centralize it in your API, focusing your efforts on client-side development.&lt;/p&gt;




&lt;h3&gt;
  
  
  2. &lt;strong&gt;Faster Development Velocity&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Once the API is in place, app development becomes exponentially faster. Why? Because your frontend developers can work independently. They no longer need to wait for backend updates—they simply consume the API according to its defined processes and constraints. &lt;/p&gt;

&lt;p&gt;The result? New features and applications can be rolled out at lightning speed.&lt;/p&gt;




&lt;h3&gt;
  
  
  3. &lt;strong&gt;A Gateway to Innovation&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;APIs aren’t just for internal use. They open doors to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Integrations&lt;/strong&gt; with external systems.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Partnerships&lt;/strong&gt; that rely on data exchange.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Automation&lt;/strong&gt; that streamlines workflows.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Innovation thrives on communication, and a robust API ensures your business can connect with others seamlessly.&lt;/p&gt;




&lt;h3&gt;
  
  
  4. &lt;strong&gt;Enhanced Security&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Let’s simplify this: imagine your business is a house with 10 doors to the outside world. Securing all 10 doors is complicated, expensive, and prone to failure. Now imagine you only have &lt;strong&gt;one door&lt;/strong&gt; to secure—that’s what an API can do for your system.&lt;/p&gt;

&lt;p&gt;By funneling all interactions through a single API, you reduce your security risks and can invest more effectively in protecting that one gateway.&lt;/p&gt;




&lt;h3&gt;
  
  
  5. &lt;strong&gt;Streamlined Team Organization&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;An API doesn’t just benefit your apps; it benefits your development team. Here’s how:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Dedicated API team&lt;/strong&gt;: A focused group can maintain and optimize the API.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Frontend independence&lt;/strong&gt;: Developers consuming the API can work more autonomously, reducing bottlenecks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Improved collaboration&lt;/strong&gt;: Clear API documentation acts as a contract between teams, minimizing misunderstandings.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Don’t Skip the Roots
&lt;/h2&gt;

&lt;p&gt;Building an API isn’t a glamorous task, but it’s essential. Think of it as the backbone of your entire digital ecosystem. Whether it’s GraphQL, REST, SOAP, or even simple HTTP requests, what matters is having a clear, secure, and well-documented communication system for your applications.&lt;/p&gt;

&lt;p&gt;The next time you’re planning a project, don’t overlook the API. It’s not just a piece of infrastructure—it’s the foundation of innovation, speed, and scalability.&lt;/p&gt;




&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Martin Fowler&lt;/strong&gt; - &lt;a href="https://martinfowler.com/" rel="noopener noreferrer"&gt;API Design Principles&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Postman Blog&lt;/strong&gt; - &lt;a href="https://blog.postman.com/" rel="noopener noreferrer"&gt;The Role of APIs in Modern Development&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Google Developers&lt;/strong&gt; - &lt;a href="https://developers.google.com/" rel="noopener noreferrer"&gt;Building APIs for Scale&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>webdev</category>
      <category>api</category>
      <category>programming</category>
      <category>backend</category>
    </item>
    <item>
      <title>Pain Points I Faced Using Serverless</title>
      <dc:creator>Durante</dc:creator>
      <pubDate>Sat, 08 Apr 2023 06:12:32 +0000</pubDate>
      <link>https://dev.to/durante/pain-points-that-i-face-working-with-serverlessand-i-hope-you-can-avoid-using-this-information-2jmo</link>
      <guid>https://dev.to/durante/pain-points-that-i-face-working-with-serverlessand-i-hope-you-can-avoid-using-this-information-2jmo</guid>
      <description>&lt;p&gt;In this article, I want to share a few challenges I've encountered while working with a serverless stack on AWS Lambda, so you can learn from my experience.&lt;/p&gt;

&lt;p&gt;For reference, the stack I use includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Lambda&lt;/li&gt;
&lt;li&gt;SQS&lt;/li&gt;
&lt;li&gt;API Gateway&lt;/li&gt;
&lt;li&gt;S3&lt;/li&gt;
&lt;li&gt;RDS&lt;/li&gt;
&lt;li&gt;Several other AWS Lambda services.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Disclaimer: While I have gained expertise through my experience, I am not an expert in this field. If you have any ideas on how I can avoid these problems or if you have faced similar situations, please share! I am eager to learn and improve.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources handling and deployment
&lt;/h2&gt;

&lt;p&gt;In a serverless stack like this, everything is a function, and all the functions are independent. While this can be great, it requires handling each function independently, for REAL. There is not just one deploy; there are many deploys, and a lot of configuration between functions (security groups, variables, dependencies, etc.).&lt;/p&gt;

&lt;p&gt;It is important to plan ahead when dealing with a complex system, as it can quickly become a nightmare, especially if you have a medium team.&lt;/p&gt;

&lt;p&gt;For small projects, you can manually create your functions using the AWS console. However, for larger projects, you will need a tool (or tools) to help manage them.&lt;/p&gt;

&lt;p&gt;Here are a few tools that I have used (or have heard about) that you can use to fix (or at least help you):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://aws.amazon.com/serverless/sam/"&gt;AWS Serverless Application Model (SAM)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.serverless.com/"&gt;Serverless Framework&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://aws.github.io/chalice/"&gt;AWS Chalice&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I personally use SAM, which is essentially CloudFormation with extra features to work easily with Lambda. It has a few limitations, such as the number of functions you can create and the configuration of API Gateway that you can use, but overall, it's a pretty good tool. It can help you feel like you are working on an integrated project instead of feeling like you are working on many connected projects.&lt;/p&gt;

&lt;p&gt;These are just a few recommendations, and there are several tools available right now to manage serverless functions. The selection will depend on your project's needs, programming language, and other architectural concerns that you have. I like SAM because it is supported by the AWS team, it's easy to use, and it's based on CloudFormation, which gives you a lot of advantages in the AWS documentation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Share code between function
&lt;/h2&gt;

&lt;p&gt;This is similar to the problem above but has another solution. So, you know that our code is independent, REAL independent. Imagine the function like an app, so you will need to share code between apps. To solve this, there are several ways we use a couple of them:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Monorepo: put all the lambda in 1 repo and use the code between them. The pro is that all code is in one place, so there are no limitations to using it. The con is that all the lambda will have this code in the artifact, so you will have the same code deployed in each lambda. That's not really a BIG problem you may think, but remember you instance the lambda function when it's called (not always, but time to time let's keep it simple). So, if you need to rebuild the app with a lot of code, you will lose performance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Lambda Layer: the AWS native solution for this is basically a dependency, but AWS handles it for us and it's previously processed. The pro is that it's the faster option and one of the simplest. The con is that it's a native way, so if you need to move your code, you will need an option in the next provider.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Library: basically, it's just a library that you will install using something like pip, npm, or the package manager that you want. The pro is that it's the most standard and simple way to do it. The con is the same as splitting your repos; you will need to handle the package (send it to npm or pip, tag it, deploy it, etc.).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In summary, the selection depends on your needs. These options are just possible solutions for how to handle it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lambda Quotes
&lt;/h2&gt;

&lt;p&gt;I have to admit, dealing with the limitations of serverless architecture can be frustrating. However, these limitations are in place to ensure functionality and stability.&lt;/p&gt;

&lt;p&gt;There are several limitations that I have had to navigate while working with serverless architecture. Some of the most common limitations include the following.&lt;/p&gt;

&lt;h3&gt;
  
  
  Execution time
&lt;/h3&gt;

&lt;p&gt;Lambda functions have a maximum execution time of 15 minutes. Therefore, you need to ensure that your function can perform its task within that time frame. While you certainly wouldn't want an API user waiting for 15 minutes, there are plenty of use cases where longer processing times are required, such as video processing, batch processing, sending email or notifications, or data extraction.&lt;/p&gt;

&lt;p&gt;To overcome this limitation, it's essential to design your system using the following techniques:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Async Endpoints: These endpoints don't return information immediately. Instead, they take the request, process it asynchronously, and then you can request the result using the same endpoint or another.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Message Queue: Take the request and the information you need to process and split it into smaller chunks of information. Send these chunks to an SQS queue and then process them with one or more lambda functions. This approach works well with Lambda and offers several advantages.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cache: Pre-process information and use Lambda to return the information to the user or other services. This reduces the amount of processing required by the Lambda function.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Webhooks: Instead of consuming and processing information, use webhooks to keep the system updated and process only what changes. This helps reduce the processing time required by the Lambda function.. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Environments variables size
&lt;/h3&gt;

&lt;p&gt;Lambda has a limitation of only supporting up to 4 kilobytes in environment variables. While I'm a big fan of environment variables because they can make a system testable and independent of the environment, it's important to be aware of this limitation.&lt;/p&gt;

&lt;p&gt;To work around this issue, we tokenize the environment variables to reduce their size, and use an external system to consume the information that we need when the lambda is initialized. This adds a bit more complexity to our system, but it's necessary to ensure that our Lambdas work properly.&lt;/p&gt;

&lt;h3&gt;
  
  
  Payload size (10 megabytes)
&lt;/h3&gt;

&lt;p&gt;When your system heavily relies on user-uploaded videos and pictures, it can pose a challenge. Initially, we attempted to simplify the process by using the base64 approach and uploading the image as part of the payload. However, Lambda and API Gateway have a limitation of 10 megabytes, and reaching out to AWS for an increase in the limit was not something we preferred to do. Due to this limitation, we had to change our approach.&lt;/p&gt;

&lt;p&gt;We chose to upload the metadata of the image and video through a REST API and use the S3 client to upload the media. Although this approach added more complexity to our system, it worked well for us. However, using the S3 client can be a little tricky due to the necessary configuration and permission requirements, especially for heavy load media.&lt;/p&gt;

&lt;h1&gt;
  
  
  Bundle/Arficat size
&lt;/h1&gt;

&lt;p&gt;When you talk about the artifact size all developers think of Android, iOS, or web pages, but in the case of serverless this is a big issue.&lt;/p&gt;

&lt;p&gt;Imaging this instead of having a server 24 hours running where you have your artifact you have several application sleeping that is waiting for a user to request then install and build themselves and when that user end up working with this the app just go to sleep and then delete itself for the memory.&lt;/p&gt;

&lt;p&gt;So based on this quick and sad history you need to be careful with the bundle size because you will need to install this from time to time.&lt;/p&gt;

&lt;p&gt;This is a simplification of the lambda livecycle:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Init: initialization of the executable, install, build, and memory allocation.&lt;/li&gt;
&lt;li&gt;Invoke: execution of our code.&lt;/li&gt;
&lt;li&gt;Shutdown: cleaning of the code and release of infrastructure.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To assure that lambda requires that every lambda follows these restrictions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;50MB for deployment: bundle compress for upload to AWS
-250MB for execution: bundle decompress including the lambda layer (all dependencies)&lt;/li&gt;
&lt;li&gt;3MB for code: your actual code need to be less than 3MB to be able to edit in the console if you use Monorepo or a direct dependency to shared code between lambda this is going to be a problem because all your project will need to be less than 3MB.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is pretty tricky for a large project but these are a couple of actions that we do to accomplish this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Remove unused dependency: Identify dependencies that are for development, not in use, or only used for scripting. These dependencies are not part of the runtime.&lt;/li&gt;
&lt;li&gt;Identify dead code: Remove any code that is not being executed in your application.&lt;/li&gt;
&lt;li&gt;Stick to what is necessary: Only write the code necessary for the solution to function.&lt;/li&gt;
&lt;li&gt;Limit each function to the necessary dependency: Each function or endpoint should be limited to the code necessary for its operation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Serveless is an interesting stack, like all tools it has its limitation and advantage you only need to have a positive attitude and learn and you can overcome the challenges. &lt;/p&gt;

&lt;p&gt;I hope you learn a little something, let me know if you have any questions or suggestions. &lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  Lambda quotas: &lt;a href="https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html"&gt;https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  Env size: &lt;a href="https://aws.amazon.com/premiumsupport/knowledge-center/lambda-environment-variable-size/"&gt;https://aws.amazon.com/premiumsupport/knowledge-center/lambda-environment-variable-size/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  Lifecycle of Lambdas: &lt;a href="https://docs.aws.amazon.com/lambda/latest/dg/runtimes-context.html#runtimes-lifecycle-ib"&gt;https://docs.aws.amazon.com/lambda/latest/dg/runtimes-context.html#runtimes-lifecycle-ib&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  Lambda layer: &lt;a href="https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html"&gt;https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  SAM: &lt;a href="https://aws.amazon.com/serverless/sam/"&gt;https://aws.amazon.com/serverless/sam/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  Serveless: &lt;a href="https://www.serverless.com/"&gt;https://www.serverless.com/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  Presigned URL: &lt;a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/ShareObjectPreSignedURL.html"&gt;https://docs.aws.amazon.com/AmazonS3/latest/userguide/ShareObjectPreSignedURL.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  Cloudformation: &lt;a href="https://aws.amazon.com/cloudformation/"&gt;https://aws.amazon.com/cloudformation/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>serverless</category>
      <category>lambda</category>
      <category>aws</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Stop Wasting Time Comparing Databases Manually! Learn How Dynamic Queries Can Save You Time and Hassle 💻🚀</title>
      <dc:creator>Durante</dc:creator>
      <pubDate>Tue, 04 Apr 2023 22:30:32 +0000</pubDate>
      <link>https://dev.to/durante/capsule-of-knowledge-that-nobody-asked-me-for-dynamic-queries-53g3</link>
      <guid>https://dev.to/durante/capsule-of-knowledge-that-nobody-asked-me-for-dynamic-queries-53g3</guid>
      <description>&lt;p&gt;In a recent project, we encountered a situation where we needed to compare two databases to ensure that all the information was successfully migrated during a server migration. To address this, I suggested using a technique called dynamic queries to compare the databases programmatically.&lt;br&gt;
 &lt;br&gt;
"Dynamic queries refer to the process of generating database queries on the fly or at runtime, rather than hard-coding them into an application. In other words, instead of having pre-defined SQL statements that are executed against a database, dynamic queries allow you to build SQL statements dynamically based on certain criteria or conditions. This can be achieved using input parameters, database catalogs, conditions, and other dynamic elements." Chat GPT (thanks)&lt;br&gt;
 &lt;br&gt;
For our specific case, we needed to extract the number of rows from all tables in the database so we could compare them between the two databases and verify if everything was properly migrated. This task could be daunting if done manually, especially when dealing with a large number of tables (e.g., 300, 100, etc.). However, using dynamic queries, we were able to automate the process and save time.&lt;br&gt;
 &lt;br&gt;
Here's an example of how we used dynamic queries with PostgreSQL catalog to generate a new query:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="s1"&gt;'SELECT COUNT(*) AS row_numbers, &lt;/span&gt;&lt;span class="se"&gt;''&lt;/span&gt;&lt;span class="s1"&gt;'&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="k"&gt;table_name&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="se"&gt;''&lt;/span&gt;&lt;span class="s1"&gt; AS table FROM '&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="k"&gt;table_name&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="s1"&gt;' UNION ALL '&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;information_schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tables&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;table_schema&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'pg_catalog'&lt;/span&gt;
&lt;span class="k"&gt;UNION&lt;/span&gt; &lt;span class="k"&gt;ALL&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="s1"&gt;'SELECT 0, &lt;/span&gt;&lt;span class="se"&gt;''&lt;/span&gt;&lt;span class="s1"&gt;dummy&lt;/span&gt;&lt;span class="se"&gt;''&lt;/span&gt;&lt;span class="s1"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt; &lt;br&gt;
&lt;strong&gt;The generated query looks like this:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;row_numbers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'pg_stat_xact_user_functions'&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="k"&gt;table&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;pg_stat_xact_user_functions&lt;/span&gt; &lt;span class="k"&gt;UNION&lt;/span&gt; &lt;span class="k"&gt;ALL&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;row_numbers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'pg_stat_archiver'&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="k"&gt;table&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;pg_stat_archiver&lt;/span&gt; &lt;span class="k"&gt;UNION&lt;/span&gt; &lt;span class="k"&gt;ALL&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;row_numbers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'pg_stat_bgwriter'&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="k"&gt;table&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;pg_stat_bgwriter&lt;/span&gt; &lt;span class="k"&gt;UNION&lt;/span&gt; &lt;span class="k"&gt;ALL&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;row_numbers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'pg_stat_progress_analyze'&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="k"&gt;table&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;pg_stat_progress_analyze&lt;/span&gt; &lt;span class="k"&gt;UNION&lt;/span&gt; &lt;span class="k"&gt;ALL&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'dummy'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt; &lt;br&gt;
&lt;strong&gt;And the result of the generated query would be:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="n"&gt;row_numbers&lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="k"&gt;table&lt;/span&gt;
&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="n"&gt;pg_stat_xact_user_functions&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="n"&gt;pg_stat_archiver&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="n"&gt;pg_stat_bgwriter&lt;/span&gt;
&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="n"&gt;pg_stat_progress_analyze&lt;/span&gt;
&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="n"&gt;dummy&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt; &lt;br&gt;
I hope you find this information useful for your future projects or as a new tool in your toolkit! this can be a powerful technique to generate database queries on the fly or just a time saver when you need to run some maintenance tasks or fix some problem&lt;/p&gt;

&lt;p&gt;Let me know if you have any questions, if you face a similar situation in the past, or if this is helpful to you! Happy coding!🤗&lt;/p&gt;

&lt;p&gt;❗️❗️No programmer or tech lead was harmed in the making of this article.❗️❗️&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>programming</category>
      <category>database</category>
      <category>devlive</category>
    </item>
  </channel>
</rss>
