How to get file extension from filename in postgresql?

by dalton_moen , in category: MySQL , 9 months ago

How to get file extension from filename in postgresql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by aubrey , 9 months ago

@dalton_moen 

You can get the file extension from a filename in PostgreSQL by using the substring function along with regular expressions. Here is an example query:

1
SELECT substring('example.txt' from '.(w+)$') as file_extension;


In this query, 'example.txt' is the filename from which you want to extract the file extension. The regular expression '.(w+)$' is used to match the last occurrence of a period followed by one or more word characters at the end of the filename, which represents the file extension. The substring function then extracts and returns the matched file extension.


This query will return the file extension of the given filename, in this case, it will return txt.

Related Threads:

How to set the filename for a downloadable file in laravel?
How to check the extension of uploading file in vue.js?
How to remove the .php extension in .htaccess file?
How to filter by a file extension in a graphql query?
How to change doxygen to not use any file extension?
How to add ".php" extension using ".htaccess" file?